/*******************************************************************************
 * Copyright (c) Jonathan Buck - jonbuck16@gmail.com
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    jonbuck16@gmail.com - initial API and implementation
 *******************************************************************************/
package net.jonbuck.tassoo.ui.util;

import java.util.Date;

import org.eclipse.jface.databinding.swt.WidgetValueProperty;
import org.eclipse.nebula.widgets.calendarcombo.CalendarCombo;
import org.eclipse.swt.SWT;

/**
 * 
 * 
 * @since 1.0.0
 */
public class CalendarComboWidgetValueProperty extends WidgetValueProperty {

	/**
	 * 
	 */
	public CalendarComboWidgetValueProperty() {
		super(SWT.Modify);
	}

	/**
	 * 
	 */
	public Object getValueType() {
		return Date.class;
	}

	/**
	 * 
	 */
	protected Object doGetValue(Object source) {
		CalendarCombo calendar = (CalendarCombo) source;
		if (calendar != null && calendar.getDate() != null && calendar.getDate().getTime() != null) {
			return calendar.getDate().getTime();
		}
		return null;
	}

	/**
	 * 
	 */
	protected void doSetValue(Object source, Object value) {
		CalendarCombo calendar = (CalendarCombo) source;
		calendar.setDate((Date) value);
	}

}
